<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="内容id" prop="contentId">
        <el-input v-model="queryParams.contentId" placeholder="请输入内容id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="审核状态" prop="examineState">
        <el-select v-model="queryParams.examineState" placeholder="请选择审核状态" @change="choosezhuang">
          <el-option v-for="dict in dict.type.examine_state" :key="dict.value" :label="dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>
      <!--  <el-form-item label="审核人员id" prop="examineUserid">
        <el-input
          v-model="queryParams.examineUserid"
          placeholder="请输入审核人员id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核未通过原因" prop="examineFailedReason">
        <el-input
          v-model="queryParams.examineFailedReason"
          placeholder="请输入审核未通过原因"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核时间" prop="examineTime">
        <el-date-picker clearable
          v-model="queryParams.examineTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择审核时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="提交审核时间" prop="submitTime">
        <el-date-picker clearable
          v-model="queryParams.submitTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择提交审核时间">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:examine:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:examine:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:examine:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:examine:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="examineList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" label="序号" width="50">
      </el-table-column>

      <!-- <el-table-column label="${comment}" align="center" prop="examineId" /> -->
      <!-- <el-table-column label="内容id" align="center" prop="contentId" /> -->
      <!-- <el-table-column label="内容类型：1：图文内容，2：素材管理" align="center" prop="contentType" /> -->

      <!-- <el-table-column label="审核人员id" align="center" prop="examineUserid" /> -->
      <el-table-column label="作者" align="center" prop="article" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.article.author }}</span>
        </template>
      </el-table-column>
      <el-table-column label="标题" align="center" prop="article" width="180">
        <template slot-scope="scope">
          <span :title="scope.row.article.title" v-if="scope.row.article.title && scope.row.article.title.length > 35">{{
            scope.row.article.title.substr(0, 35) }}...</span>
          <span v-else>{{ scope.row.article.title }}</span>

        </template>
      </el-table-column>
      <el-table-column label="内容简介" align="center" prop="article" width="300">
        <template slot-scope="scope">
          <span :title="scope.row.article.digest" v-if="scope.row.article.digest && scope.row.article.digest.length > 35">{{
            scope.row.article.digest.substr(0, 35) }}...</span>
          <span v-else>{{ scope.row.article.digest }}</span>

        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="examineState">

        <template slot-scope="scope">
          <el-tag v-if="scope.row.examineState == 0" type="info">待审核</el-tag>
          <el-tag v-if="scope.row.examineState == 1" type="success">审核通过</el-tag>
          <el-tag v-if="scope.row.examineState == 2" type="warning">审核未通过</el-tag>
          <el-tag v-if="scope.row.examineState == 3" type="warning">审核未通过</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="审核意见" align="center" prop="examineFailedReason" />
      <!-- <el-table-column label="审核类型：   0：版权审核，1：一审，2：二审" align="center" prop="examineType" /> -->
      <el-table-column label="审核时间" align="center" prop="examineTime" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.examineTime }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="提交审核时间" align="center" prop="submitTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submitTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="备注" align="center" prop="failedNotes" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:examine:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:examine:remove']"
          >删除</el-button> -->
          <el-button size="mini" type="text" @click="handleUpdate(scope.row)">二级审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog title="详情" :visible.sync="open" width="800px" append-to-body>
      <div>
        <div class="title" style="width: 100%;text-align: center;font-size: 20px;font-weight: bold;line-height: 50px;">{{
          article.title }}</div>
        <div class="" style="width: 100%;text-align: center;font-size: 14px;color: #999;line-height: 30px;">作者：{{
          article.author ? article.author : "无" }}</div>
        <div class="content" v-html="article.content" style="width: 100%;padding: 10px;padding-bottom: 50px;"></div>
        <!-- <el-divider></el-divider>
       <div style="font-size: 20px;font-weight: bold;"><div style="padding-bottom: 20px;">版权文件</div>  <el-button
          type="success"
          plain
          size="small"
          @click="chakan(article.copyrightUrl)"
        > 查看文件 </el-button></div> -->
      </div>
      <el-divider></el-divider>
      <div style="font-size: 20px;font-weight: bold;">
        <div style="padding-bottom: 20px;">审核意见</div>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="审核状态" prop="examine_state">
            <el-radio v-model="form.examine_state" label="1">审核通过</el-radio>
            <el-radio v-model="form.examine_state" label="2">审核驳回</el-radio>
          </el-form-item>
          <el-form-item label="审核意见" prop="examineFailedReason">
            <el-input type="textarea" placeholder="请输入审核意见或改进措施" v-model="form.examineFailedReason" maxlength="100"
              show-word-limit style="width: 500px;" rows="5">
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listExamine, getExamine, delExamine, addExamine, updateExamine, ershen } from "@/api/system/examine";

export default {
  name: "Examine",
  dicts: ['examine_state'],

  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      article: "",
      // 【请填写功能名称】表格数据
      examineList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contentId: null,
        contentType: null,
        examineUserid: null,
        examineFailedReason: null,
        examineType: null,
        examineTime: null,
        submitTime: null,
        failedNotes: null,
        examineState: "0",
        examineType: "2"
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        examine_state: [
          { required: true, message: "请审核", trigger: "blur" }
        ],
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {
    chakan(url) {
      window.open(url)
    },
    choosezhuang() {
      this.getList()
    },
    banshen() {

    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listExamine(this.queryParams).then(response => {
        this.examineList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        examineId: null,
        contentId: null,
        contentType: null,
        examineState: null,
        examineUserid: null,
        examineFailedReason: null,
        examineType: null,
        examineTime: null,
        submitTime: null,
        createTime: null,
        failedNotes: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.examineId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const examineId = row.examineId || this.ids
      getExamine(examineId).then(response => {
        this.form = response.data;
        this.article = response.data.article
        console.log(this.form)
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.examine_state == '1') {
            let obj = {}
            obj.examineId = this.form.examineId
            obj.contentId = this.form.contentId
            obj.examineState = this.form.examine_state
            obj.examineFailedReason = this.form.examineFailedReason
            if (this.form.examineId != null) {
              ershen(obj).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            }
          }
        }
        if (this.form.examine_state == '2') {
          if (this.form.examineFailedReason) {
            let obj = {}
            obj.examineId = this.form.examineId
            obj.contentId = this.form.contentId
            obj.examineState = this.form.examine_state
            obj.examineFailedReason = this.form.examineFailedReason
            if (this.form.examineId != null) {
              ershen(obj).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            }
          } else {
            this.$message.warning(`请填写审核意见`);
          }

        }

      });
      // this.$refs["form"].validate(valid => {
      //   if (valid) {
      //   let obj={}
      //   obj.examineId=this.form.examineId
      //   obj.contentId=this.form.contentId
      //   obj.examineState=this.form.examine_state
      //     if (this.form.examineId != null) {
      //       ershen(obj).then(response => {
      //         this.$modal.msgSuccess("修改成功");
      //         this.open = false;
      //         this.getList();
      //       });
      //     } 
      //   }
      // });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const examineIds = row.examineId || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + examineIds + '"的数据项？').then(function () {
        return delExamine(examineIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/examine/export', {
        ...this.queryParams
      }, `examine_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style  l>
.content img {

  width: 100% !important;
}
</style>
